<template>
  <div class="problemList bg-f2">
    <div class="bg-f2 bg-fff">
      <div class="addMargin">
        <!-- <el-button class="increased" icon="el-icon-plus" @click="addUser('录入系统巡检单')">录入系统巡检单</el-button> -->
        <el-form :inline="true" class="formLine">
          <el-form-item class="formLine_item">
            <el-button class="btnSizeStyle" type="success" icon="el-icon-plus" :disabled="quanxianBtns.btn1" @click="addUser('录入巡检单')">录入巡检单</el-button>
          </el-form-item>
          <el-form-item class="formLine_item" label="所属机构：">
            <el-select v-model="searchBox.ssjg" :no-data-text="tiText1" clearable placeholder="选择机构">
              <el-option v-for="item in jgmcOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="巡检时间:" class="formLine_item">
            <el-date-picker
              v-model="searchBox.xjsj"
              :picker-options="pickerBeginDateBefore"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
          <el-form-item class="formLine_item">
            <el-input v-model.trim="searchBox.searchValue" clearable placeholder="输入巡检人姓名" prefix-icon="el-icon-search"></el-input>
          </el-form-item>
          <el-form-item class="formLine_item">
            <el-button @click="searchBtn2()" type="primary" class="btnSizeStyle">查询</el-button>
            <!-- <el-button plain type="primary">打印</el-button> -->
          </el-form-item>
        </el-form>
      </div>
      <el-table
        border
        stripe
        :header-cell-style="{ backgroundColor: '#ECF3FC', color: '#333', height: '48px', borderBottom: '1px solid #CEE1F7' }"
        highlight-current-row
        ref="multipleTable"
        :data="contractList"
        style="width: 100%"
        :default-sort="{ prop: 'deviceName' }"
        v-loading="tableLoad"
      >
        <!-- 提示语句 -->
        <template slot="empty">{{ tableMessage }}</template>
        <el-table-column type="index" label="序号" min-width="50" align="center" />
        <el-table-column prop="ssjgmc" label="所属机构" show-overflow-tooltip min-width="120"></el-table-column>
        <el-table-column prop="spxl" label="视频巡逻">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.spxl - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.qdrq - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column prop="lxhf" label="录像回放">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.lxhf - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.lxhf - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->

            <!-- <svg
            v-show="scope.row.qdrq === 1 ? false : true"
            class="iconfont"
            style="width: 12px;height: 12px;vertical-align: middle;"
          >
            <use xlink:href="#el-icon-mygenerated" style="font-size:50px" />
          </svg>
          <svg
            v-show="scope.row.qdrq === 1 ? true : false"
            class="iconfont"
            style="width: 12px;height: 12px;vertical-align: middle;"
          >
            <use xlink:href="#el-icon-mywarning" style="font-size:50px" />
            </svg>-->
          </template>
        </el-table-column>
        <el-table-column label="电视墙" show-overflow-tooltip>
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.dsq - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.dsq - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column label="电子地图">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.dzdt - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.dzdt - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column label="视频地图" prop="spdt">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.spdt - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.spdt - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column prop="clcx" label="车辆查询">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.clcx - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.clcx - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column prop="qdrq" label="人脸查询">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.rlcx - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.rlcx - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column prop="qdrq" label="枪球联动">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.qqld - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.qqld - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column prop="qdrq" label="平台日志">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" :content="scope.row.ptrz - '' === 1 ? '故障' : '正常'" placement="top"> -->
            <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
              <use :xlink:href="'#el-icon-my' + (scope.row.ptrz - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
            </svg>
            <!-- </el-tooltip> -->
          </template>
        </el-table-column>
        <el-table-column prop="gzxxms" label="故障描述" min-width="150">
          <template slot-scope="scope">
            <el-tooltip effect="dark" placement="top-start" v-show="scope.row.gzxxms === null || scope.row.gzxxms.length > 41 ? true : false">
              <div slot="content" style="width: 400px">{{ scope.row.gzxxms }}</div>
              <span :class="scope.row.gzxxms === null || scope.row.gzxxms.length > 41 ? 'usersNumber' : ''">{{ scope.row.gzxxms }}</span>
            </el-tooltip>
            <span v-show="scope.row.gzxxms === null || scope.row.gzxxms.length > 41 ? false : true">{{ scope.row.gzxxms }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="xjjgmc" label="巡检机构" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="xjrzsxm" label="巡检人" min-width="100"></el-table-column>
        <el-table-column prop="zp" label="巡检单" min-width="65">
          <template slot-scope="scope">
            <el-image style="width: 43px; height: 40px" :src="scope.row.zp ? scope.row.zp[0].url : ''" :preview-src-list="yuLanTP(scope.row.zp)">
              <div slot="error">
                <img style="width: 100%" src="@/assets/images/shan.jpg" alt />
              </div>
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="巡检时间" width="100">
          <template slot-scope="scope">{{ scope.row.xjsj | dateFormat2 }}</template>
        </el-table-column>
        <el-table-column label="添加时间" width="100">
          <template slot-scope="scope">{{ scope.row.tjsj | dateFormat }}</template>
        </el-table-column>
        <el-table-column label="操作" align="right" min-width="150" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" class="Btn_nan" :disabled="quanxianBtns.btn3" @click="addUser('编辑巡检单', scope.row)">编辑</el-button>
            <span class="operation"></span>
            <el-button type="text" class="Btn_nan" @click="userBox(scope.row)">详情</el-button>
            <span class="operation"></span>
            <el-button :disabled="quanxianBtns.btn2" type="text" size="small" class="color_f56f6f Btn_nan" @click="deteleJD(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- <div class="fooer_box">
        <div></div>
        <el-pagination
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next"
          :total="countList"
        ></el-pagination>
      </div>-->
      <!-- 分页 -->
      <el-row class="page-row">
        <el-col :span="12">
          <div class="bigBOx btnBefore">
            <div class="imgBox">
              <svg class="iconfont imgIcon" aria-hidden="true">
                <use xlink:href="#el-icon-mygenerated" />
              </svg>
              <span>正常</span>
            </div>
            <div class="imgBox">
              <svg class="iconfont imgIcon" aria-hidden="true">
                <use xlink:href="#el-icon-mywarning" />
              </svg>
              <span>异常</span>
            </div>
          </div>
        </el-col>
        <el-col :span="12" style="height: 47px; display: table">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next"
            :total="countList"
          ></el-pagination>
        </el-col>
      </el-row>
      <!-- 卡口详情 -->
      <el-dialog title="巡检单详情" :visible.sync="contractDialogVisible">
        <div class="dialogText">
          <el-row>
            <el-col :span="12" class="lineHight">
              <el-row>
                <span class="contentFont">所属机构：</span>
                <span>{{ xianqingye.ssjgmc }}</span>
              </el-row>
              <el-row>
                <span class="contentFont">巡检机构：</span>
                <span>{{ xianqingye.xjrzsxm }}</span>
              </el-row>
              <el-row>
                <span class="contentFont">巡检时间：</span>
                <span>{{ xianqingye.xjsj | dateFormat2 }}</span>
              </el-row>
              <el-row>
                <span class="contentFont">添加时间：</span>
                <span>{{ xianqingye.tjsj | dateFormat }}</span>
              </el-row>
              <el-row>
                <span class="contentFont">视频巡逻：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.qdrq - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">录像回放：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.lxhf - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">电视墙：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.dsq - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">电子地图：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.dzdt - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
            </el-col>
            <el-col :span="12" class="lineHight">
              <el-row>
                <span class="contentFont">视频地图：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.spdt - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">车辆查询：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.clcx - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">人脸查询：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.rlcx - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">枪球联动：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.qqld - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">平台日志：</span>
                <span>
                  <svg class="iconfont" style="width: 12px; height: 12px; vertical-align: middle">
                    <use :xlink:href="'#el-icon-my' + (xianqingye.ptrz - '' === 1 ? 'warning' : 'generated')" style="font-size: 50px" />
                  </svg>
                </span>
              </el-row>
              <el-row>
                <span class="contentFont">故障描述：</span>
                <span>{{ xianqingye.gzxxms }}</span>
              </el-row>
              <el-row>
                <span class="contentFont">巡检单：</span>
                <el-image style="width: 60px; height: 60px; vertical-align: middle" :src="xianqingye.zpArry[0]" :preview-src-list="xianqingye.zpArry">
                  <div slot="error" class="image-slot">
                    <i class="el-icon-picture-outline"></i>
                  </div>
                </el-image>
              </el-row>
            </el-col>
          </el-row>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="contractDialogVisible = false" class="btnSizeStyle">关 闭</el-button>
        </div>
      </el-dialog>
      <!-- 删除 -->
      <el-dialog title="删除" :visible.sync="dialogVisibleDetele" width="30%">
        <span>您确定要删除吗？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleDetele = false" class="btnSizeStyle">取 消</el-button>
          <el-button type="primary" @click="deleteItem" v-preventReClick class="btnSizeStyle">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { getUrl } from '@/utils/getUrl.js'
import { pinT, xunJian } from '@/utils/allUrl.js'
// import { endLoading } from '@/utils/loading.js'
import { timeLoad, tableMessageText } from '@/assets/js/setTime'
export default {
  data: function () {
    return {
      currentPage: 1,
      pageSize: 10,
      contractList: [],
      countPage: 0,
      countList: 0,
      // 机构
      jgmcOptions: [],
      contractDialogVisible: false, // 详情
      xianqingye: {
        zpArry: [], // 初始化图片数组
        gzxxms: '', // 初始化故障
      }, // 详情数据
      dialogVisibleDetele: false, // 删除
      searchBox: {
        ssjg: '',
        xjsj: '',
        searchValue: '',
      },
      deleteID: '', // 删除id
      pickerBeginDateBefore: {
        // 设置只能选择到今天及以前的日期
        disabledDate(time) {
          return time.getTime() >= Date.now()
        },
      },
      tableMessage: '',
      tableTimer: null,
      tiText1: '暂无数据', // 机构提示
      quanxianBtns: {
        btn1: true,
        btn2: true,
        btn3: true,
      },
    }
  },
  watch: {
    tableLoad(newVal, oldVal) {
      this.tableTimer = setTimeout(() => {
        if (this.tableLoad) {
          this.tableLoad = false
          this.tableMessage = tableMessageText
          this.contractList = []
          // this.countList = 0
        }
      }, timeLoad)
    },
  },
  created: function () {
    // 权限按钮
    this.jurisdictionBtn()
    this.getContractList()
    // 获取所属机构
    this.getMechanism()
  },
  methods: {
    // 获取按钮权限
    jurisdictionBtn() {
      const menus = JSON.parse(getUrl('jurisdiction'))
      menus.forEach((item) => {
        if (item.qxdm === 'XJZX_XTXJD_XTGNXJD') {
          item.children.forEach((item2) => {
            if (item2.qxdm === 'xtxjd:create') {
              this.quanxianBtns.btn1 = false // 录入系统巡检单
            } else if (item2.qxdm === 'xtxjd:delete') {
              this.quanxianBtns.btn2 = false // 删除
            } else if (item2.qxdm === 'xtxjd:update') {
              this.quanxianBtns.btn3 = false // 编辑
            }
          })
        }
      })
    },
    // 获取数据
    getContractList() {
      clearTimeout(this.tableTimer)
      this.tableLoad = true
      const params = new URLSearchParams()
      params.append('M_', this.currentPage)
      params.append('N_', this.pageSize)
      this.getList(params)
    },
    // 获取机构
    async getMechanism() {
      const { data: res } = await this.$http.post(`${pinT}zzjg/list`)
      if (res.code !== '0000') {
        this.jgmcOptions = []
        this.tiText1 = res.message
      } else {
        const a = JSON.stringify(res.data.list)
        const newCity = a.replace(/id/g, 'value')
        const cityList = newCity.replace(/jgmc/g, 'label')
        const cityList2 = cityList.replace(/jgbmmc/g, 'label')
        const c = cityList2.replace(/bmList/g, 'children')
        this.jgmcOptions = JSON.parse(c)
      }
    },
    handleSizeChange(e) {
      this.currentPage = 1
      this.pageSize = e
      this.searchBtn()
    },
    handleCurrentChange(e) {
      this.currentPage = e
      this.searchBtn()
    },
    addUser(title, scope) {
      if (title === '录入巡检单') {
        this.$router.push({
          name: 'addSystemInspection', // 路由
          query: {
            // 传递参数
            title: title,
          },
        })
      } else {
        this.$router.push({
          name: 'addSystemInspection', // 路由
          query: {
            // 传递参数
            title: title,
            content: scope.id,
          },
        })
      }
    },
    yuLanTP(val) {
      const arr = []
      if (val) {
        val.forEach((item) => {
          arr.push(item.url)
        })
      }
      return arr
    },
    // 详情
    userBox(scope) {
      const arr = []
      if (scope.zp) {
        scope.zp.forEach((item) => {
          arr.push(item.url)
        })
      }
      this.xianqingye = scope
      this.xianqingye.zpArry = arr
      this.contractDialogVisible = true
    },
    // 删除
    deteleJD(scope) {
      this.dialogVisibleDetele = true
      this.deleteID = scope.id
    },
    async deleteItem() {
      const params = new URLSearchParams()
      params.append('ID', this.deleteID)
      const { data: res } = await this.$http.post(`${xunJian}xtxjd/delete`, params)
      if (res.code !== '0000') {
        return this.$message({
          type: 'error',
          message: res.message,
          center: true,
        })
      }
      this.$message({
        type: 'success',
        message: res.message,
        center: true,
      })
      this.dialogVisibleDetele = false
      this.getContractList()
    },
    searchBtn2() {
      this.currentPage = 1
      this.pageSize = 10
      this.searchBtn()
    },
    searchBtn() {
      clearTimeout(this.tableTimer)
      this.tableLoad = true
      const params = new URLSearchParams()
      const { ssjg, xjsj, searchValue } = this.searchBox
      if (xjsj !== null) {
        params.append('KSXJSJ', xjsj[0] || '')
        params.append('JSXJSJ', xjsj[1] || '')
      }
      params.append('SSJG_ID', ssjg)
      params.append('XJRZXSM', searchValue)
      params.append('M_', this.currentPage)
      params.append('N_', this.pageSize)
      this.getList(params)
    },
    async getList(params) {
      const { data: res } = await this.$http.post(`${xunJian}xtxjd/list`, params)
      this.tableLoad = false // 表格加载中样式
      switch (res.code) {
        case '0000': // 操作成功
          this.countList = res.data.countList
          res.data.list.forEach((item) => {
            if (item.zp) {
              item.zp = JSON.parse(item.zp)
              if (item.zp.length === 0) {
                item.zp = null
              }
            }
          })
          this.contractList = res.data.list
          break
        default:
          this.contractList = []
          this.tableMessage = res.message
          this.countList = 0
          break
      }
    },
  },
}
</script>
<style lang="scss" scoped>
.addMargin {
  .increased {
    background: rgba(103, 194, 58, 1);
    font-size: 14px;
    color: #fff;
    text-align: center;
  }
  .formLine {
    margin: 0;
    float: left;
    .formLine_item {
      padding: 0;
      margin-bottom: 15px;
    }
  }
}
.addMargin:after {
  content: '';
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.el-table {
  border: 1px solid #eaeaea;
  border-bottom: 0;
  .operation {
    display: inline-block;
    margin: 0 5px;
    height: 10px;
    border-left: 1px solid #b3b3b3;
  }
  .Btn_nan {
    padding: 0;
  }
  .usersNumber {
    cursor: pointer;
    overflow: hidden;
    -webkit-line-clamp: 2;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    white-space: nowrap;
    position: relative;
  }
  .usersNumber:after {
    content: '...';
    text-align: right;
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10%;
    height: 1.8em;
    background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
  }
}
.fooer_box {
  height: 48px;
  line-height: 47px;
  padding: 0 15px;
  box-sizing: border-box;
  border-top: none;
  border: 1px solid #eaeaea;
  border-top: 0;
  display: flex;
  justify-content: space-between;
  .el-pagination {
    padding: 6px 5px;
  }
}
.dialogText {
  .p_15 {
    padding-top: 15px;
  }
  font-size: 14px;
  color: #333;
  .star {
    color: #f56c6c;
  }
  .lineHight .el-row {
    line-height: 40px;
    span {
      color: #333;
      &.contentFont {
        display: inline-block;
        width: 103px;
        color: #7a7a7a;
        text-align: right;
      }
    }
  }
}
</style>
